package cfluo.test.promotion;

import java.util.ArrayList;
import java.util.List;

import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.StatelessKieSession;

import cfluo.test.fact.promotion.Customer;
import cfluo.test.fact.promotion.CustomerProRange;
import cfluo.test.fact.promotion.ProductItem;
import cfluo.test.fact.promotion.PromotionInput;
import cfluo.test.fact.promotion.PromotionOutput;
import util.KnowledgeSessionHelper;

public class PromotionTest1 {
	static KieContainer kieContainer;
	StatelessKieSession sessionStateless = null;
	KieSession sessionStatefull = null;

	@BeforeClass
	public static void beforeClass() {
		kieContainer = KnowledgeSessionHelper.createRuleBase();
	}
	@Test
	public void testPromotion1(){
		 sessionStatefull = KnowledgeSessionHelper
	                .getStatefulKnowledgeSession(kieContainer, "promotion-session1");
		 PromotionOutput output = new PromotionOutput();
		 PromotionInput input = new PromotionInput();
		 Customer customer = new Customer();
		 customer.setIsVip(true);
		 ProductItem productItem = new ProductItem();
		 productItem.setProdName("测试商品1");
		 productItem.setPrice(100d);
		 productItem.setProdCode("00001");
		 ProductItem productItem2 = new ProductItem();
		 productItem2.setProdName("测试商品XX");
		 productItem2.setPrice(100d);
		 productItem2.setProdCode("00008");
		 ProductItem productItem3 = new ProductItem();
		 productItem3.setProdName("测试商品3");
		 productItem3.setPrice(160d);
		 productItem3.setProdCode("00003");
		 CustomerProRange customerProRange = new CustomerProRange();
		 List<ProductItem> prodList=new ArrayList<ProductItem>();
		 prodList.add(productItem);
		 prodList.add(productItem2);
		 prodList.add(productItem3);
		 input.setProdList(prodList);
		 //sessionStatefull.setGlobal("output", output);
		 sessionStatefull.insert(customerProRange);
		 sessionStatefull.insert(customer);
		 sessionStatefull.insert(input);
		 sessionStatefull.fireAllRules();
		 sessionStatefull.dispose();
	}
}
